package com.ss.android.article.base.feature.app.browser.a;

import android.app.Activity;
import android.content.Context;
import android.net.Uri;
import android.os.Build;
import android.text.TextUtils;

import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.feature.app.e.TTAndroidObject;
import com.ss.android.common.util.ImmersedStatusBarHelper;
import com.ss.android.newmedia.a.v;
import com.ss.android.newmedia.activity.browser.BrowserActivity.OperationButton;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public final class a extends TTAndroidObject {
    public com.ss.android.newmedia.activity.browser.d a;

    public a(AppData arg1, Context arg2) {
        super(arg1, arg2);
    }

    private void a(boolean arg2) {
        if (this.a != null) {
            this.a.a(arg2);
        }
    }

    public final void handleUri(Uri arg3) {
        if (arg3 != null) {
            try {
                String v0_1 = arg3.getHost();
                if (android.support.design.a.isTextEmpty(v0_1)) {
                    return;
                }

                if ("disable_overlay".equals(v0_1)) {
                    Object v0_2 = this.mContextRef != null ? this.mContextRef.get() : null;
                    boolean v1 = v0_2 instanceof v;
                    if (!v1) {
                        return;
                    }

                    ((v) v0_2).c();
                    return;
                }

                super.handleUri(arg3);
            } catch (Exception v0) {
            }
        }
    }

    public final void addProtectedFeature(List<String> protectFeatureList) {
        super.addProtectedFeature(protectFeatureList);
        protectFeatureList.add("setBrowserOpBtnVisible");
        protectFeatureList.add("disableHistory");
        protectFeatureList.add("statusBar");
        protectFeatureList.add("backButton");
    }

    public final boolean processJsMsg(JSMessage jsMessage, JSONObject arg13) throws Exception {
        JSONObject v3_1;
        JSONObject v0_2;
        int v1_1 = 0;
        int v0_1;
        int v6 = 3;
        int v5 = 2;
        int v4 = -1;
        boolean v1 = false;
        String v0 = TextUtils.isEmpty(jsMessage.func) ? "" : jsMessage.func;
        switch (v0) {
            case "getStatusBarInfo": {
                v0_1 = 4;
                break;
            }
            case "setBrowserOpBtnVisible": {
                v0_1 = 0;
                break;
            }
            case "backButton": {
                v0_1 = 1;
                break;
            }
            case "statusBar": {
                v0_1 = v6;
                break;
            }
            case "disableHistory": {
                v0_1 = v5;
                break;
            }
            default: {
                label_11:
                v0_1 = v4;
                break;
            }
        }

        switch (v0_1) {
            case 0: {
                v0_2 = jsMessage.params;
                Activity v3 = this.getActivityCtx();
                if (v0_2 == null) {
                    return v1;
                }

                if (v3 == null) {
                    return v1;
                }

                if (this.a == null) {
                    return v1;
                }

                JSONArray v7 = v0_2.optJSONArray("data");
                if (v7 == null) {
                    return v1;
                }

                if (v7.length() <= 0) {
                    return v1;
                }

                ArrayList v8 = new ArrayList();
                for (v0_1 = 0; v0_1 < v7.length(); ++v0_1) {
                    v3_1 = v7.optJSONObject(v0_1);
                    if (v3_1 != null) {
                        String v9 = v3_1.optString("key");
                        int v3_2 = v3_1.optInt("visible", 1);
                        if (!android.support.design.a.isTextEmpty(v9) && v3_2 == 1) {
                            switch (v9) {
                                case "copylink": {
                                    v3_2 = 1;
                                    break;
                                }
                                case "openwithbrowser": {
                                    v3_2 = v5;
                                    break;
                                }
                                case "share": {
                                    v3_2 = v6;
                                    break;
                                }
                                case "refresh": {
                                    v3_2 = 0;
                                    break;
                                }
                                default: {
                                    label_69:
                                    v3_2 = v4;
                                    break;
                                }
                            }

                            label_70:
                            switch (v3_2) {
                                case 0: {
                                    ((List) v8).add(OperationButton.REFRESH);
                                    continue;
                                }
                                case 1: {
                                    ((List) v8).add(OperationButton.COPYLINK);
                                    continue;
                                }
                                case 2: {
                                    ((List) v8).add(OperationButton.OPEN_WITH_BROWSER);
                                    continue;
                                }
                                case 3: {
                                    ((List) v8).add(OperationButton.SHARE);
                                    continue;
                                }
                            }
                        }
                    }
                }

                this.a.a(((List) v8));
                break;
            }
            case 1: {
                v0_2 = jsMessage.params;
                if (v0_2 == null) {
                    return v1;
                }

                if (this.a == null) {
                    return v1;
                }

                String v2 = v0_2.optString("icon");
                String v3_3 = v0_2.optString("color");
                v0 = v0_2.optString("position");
                if (!android.support.design.a.isTextEmpty(v2)) {
                    this.a.b(v2);
                }

                if (!android.support.design.a.isTextEmpty(v3_3)) {
                    this.a.a(v3_3);
                }

                if (android.support.design.a.isTextEmpty(v0)) {
                    return v1;
                }

                this.a.c(v0);
                break;
            }
            case 2: {
                if (this.a == null) {
                    return v1;
                }

                this.a.e();
                break;
            }
            case 3: {
                v0 = jsMessage.params.optString("color");
                if ("white".equals(v0)) {
                    this.a(false);
                } else if ("black".equals(v0)) {
                    this.a(true);
                }

                v0 = "code";
                if ((ImmersedStatusBarHelper.isEnabled()) && Build.VERSION.SDK_INT >= 23) {
                    v1_1 = 1;
                }

                arg13.put(v0, v1_1);
                v1 = true;
                break;
            }
            case 4: {
                if (this.mContextRef.get() == null) {
                    return v1;
                }

                v3_1 = new JSONObject();
                v3_1.put("isEnable", ImmersedStatusBarHelper.isEnabled());
                v3_1.put("height", ImmersedStatusBarHelper.getStatusBarHeight((Context) this.mContextRef.get(), false));
                arg13.put("code", v3_1);
                v1 = true;
                break;
            }
            default: {
                v1 = super.processJsMsg(jsMessage, arg13);
                break;
            }
        }

        return v1;
    }

    public final void addPublicFeature(List<String> arg2) {
        super.addPublicFeature(arg2);
        arg2.add("getStatusBarInfo");
    }
}

